// components/order-list/index.js
const { updateOrderStatus } = require('../../utils/api.js');

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    orderList: {
      type: Array,
      value: [],
    },
    typeMap: {
      type: Object,
      value: {},
    },
  },

  /**
   * 组件的初始数据
   */
  data: {},

  /**
   * 组件的方法列表
   */
  methods: {
    handleStatusChange(e) {
      wx.showModal({
        title: '提示',
        content: '确定要操作吗？',
        success: (res) => {
          if (res.confirm) {
            const { item, status } = e.currentTarget.dataset;
            const params = {
              id: item.id,
              status: status,
            };
            updateOrderStatus(params).then(() => {
              wx.showToast({ title: '操作成功', icon: 'success' });
              this.triggerEvent('refresh');
            });
          }
        },
      });
    },
  },
});
